package com.hex.ds.em.hcdp.gauss.pack.service.impl;


import com.hex.ds.em.hcdp.gauss.pack.service.ISQLExtractor;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.stereotype.Component;

/**
 * @Package: com.hex.hdtp.scf.impala.analyze.py.service.impl
 * @ClassName PythonSQLExtractor
 * @Description: python中抽取sql
 * @Author: Dong shiyi
 * @Date 2023/9/8 18:07
 * @Version v1.0
 **/
@Component
public class PythonSQLExtractor implements ISQLExtractor {



  @Override
  public List<String> extractor(String sourceStr) {
    List<String> sqlList = new ArrayList<>();
    String regex = "sql = r[\"']{3};?(.*?)([\"']{3})";
    Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
    Matcher matcher = pattern.matcher(sourceStr);

    while (matcher.find()) {
      String sql = matcher.group(1).trim();
      sqlList.add(sql);
    }
    return sqlList;
  }
}
